<template>
  <div class="app-container">
    <!-- 房间背景 -->
    <reservation-list-container
      :searchItems="searchItems"
      :tableData="tableData"
      :columns="columns"
      :loading="loading"
      :total="1000"
      :showResetButton="false"
      @search="handleSearch"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      @sort-change="handleSortChange"
    >
      <template #backgroundImg="{ row }">
        <div class="image-pair">
          <el-image
            v-for="(i, index) in row.list"
            :key="index"
            :style="index === 0 ? 'width: 66px; height: 45px' : 'width: 26px; height: 45px'"
            :src="i.src"
            show-progress
            fit="cover"
            @click="handlePreview(row.list, i.id)"
          />
        </div>
      </template>
    </reservation-list-container>
    <el-image-viewer
      v-if="showPreview"
      :url-list="srcList"
      show-progress
      :initial-index="defaultIndex"
      @close="showPreview = false"
    />
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import ReservationListContainer from "@/components/PageTable/ReservationList.vue";

const srcList = ref<string[]>([]);
const defaultIndex = ref(0);

const showPreview = ref(false);
const handlePreview = (list: Array<{ src: string; id: number }>, id: number) => {
  showPreview.value = true;
  srcList.value.splice(0, srcList.value.length, ...list.map((item) => item.src));
  defaultIndex.value = id - 1;
};
// 搜索项配置
const searchItems = [
  {
    label: "状态",
    prop: "status",
    component: "el-select",
    props: {
      options: [
        { label: "永久", value: 0 },
        { label: "已过期", value: 1 },
        { label: "禁用", value: 2 },
      ],
    },
    defaultValue: null,
  },
];

// 表格列配置
const columns = [
  {
    label: "背景图",
    slot: "backgroundImg",
  },
  {
    prop: "backgroundName",
    label: "背景名称",
  },
  {
    prop: "getTime",
    label: "获取时间",
  },
  {
    prop: "indate",
    label: "有效期",
  },
  {
    prop: "status",
    label: "状态",
  },
];

// 表格数据
const tableData = ref([
  {
    list: [
      {
        id: 1,
        src: "https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
      },
      {
        id: 2,
        src: "https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg",
      },
    ],
    backgroundName: "背景名称",
    getTime: "2025-02-18 15:00:00",
    indate: "永久",
    status: "",
  },
]);

const loading = ref(false);

// 搜索方法
const handleSearch = (searchData: any) => {
  console.log("搜索操作", searchData);
};

// 分页大小变化方法
const handleSizeChange = (size: any) => {
  console.log("分页大小变化", size);
};

// 当前页变化方法
const handleCurrentChange = (page: any) => {
  console.log("当前页变化", page);
};

// 排序变化方法
const handleSortChange = (sortInfo: any) => {
  console.log("排序变化", sortInfo);
};
</script>
<style lang="scss" scoped>
.image-pair {
  display: inline-flex;
  gap: 10px;
  align-items: center;
}
</style>
